﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using WPFExcelReport.Helpers;
using System.ComponentModel;
namespace WPFExcelReport
{
    public partial class TXJGS04
    {

        public TXJGS04()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VGSMATK();
            DataContext = MV;
            InitializeComponent();

        } 
      

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);

        }
 
      
        public override void OnVAKChg(DataRow sd)
        {
            TBMain.Clear();
            if (dwVAK == null)
                return;
            if (!IsAuto)
            {
                dwData = TBMain.NewRow();
                dwData["GSMMANDANT"] = app.Mandant;
                dwData["GSMART"] = dwVAK["VAKBFARBE"].ToString().PadRight(20);
                SResult = TMV.QueryGSMATK(dwData, 6);
                MergeData(SResult, false, true);
                return;
            }
               
            for(int idx=1;idx<9;idx++)
            {
                double ratio = 0.1 * Convert.ToDouble(dwVAK["VAAGESANT" + idx].ToString());
                if (ratio == 0)
                    continue;
                string comp = dwVAK["VAAGESBEZ" + idx].ToString();
                if (comp.Trim().Length == 0) continue;
                dwData = TBMain.NewRow();
                TMV.SetUpNewRow(ref dwData);
                dwData["GSMMANDANT"] = app.Mandant;
                dwData["GSMART"] = dwVAK["VAKBFARBE"].ToString().PadRight(20);
                dwData["GSMPOS"] = Helper.Right("00" + idx, 2);
                dwData["GSMRANT"] = dwVAK["VAAGESANT" + idx].ToString();
                dwData["GSMRFARBE"] = dwVAK["VAAGESBEZ" + idx].ToString().Trim().PadRight(10);
                dwData["GSMRSPZ"] = dwVAK["VAAGESBEZ" + idx].ToString().Trim().PadRight(25);
                
                TBMain.Rows.InsertAt(dwData, 0);
                TMV.DGSM01(dwData); 
                //TMV.InsertGSMATK(dwData, app.company);
                TMV.BATCHWB14(dwData);
            }
            TMV.POSTCHG();
            base.OnVAKChg(sd);

        }
        
 
    }
}
